<?php

abstract class Core_Agent_Share_View_Grid extends Dcmp_Component_View {

    protected $grid = NULL;
    protected $filter = NULL;
    protected $toolbar = NULL;
    protected $pagination = NULL;
    
    public function __construct($component){
        $this->grid = new Kd_Html_Grid();
        $this->toolbar = new Kd_Html_Toolbar();
        $this->pagination = new Kd_Html_Pagination();
        parent::__construct($component);
    }    
    
    protected function initialize(){
    	$this->setTemplatePath(Kd_Util_IO::findFile($this->getDomain()->getConfig()->getSetting('templateDirectories'), 
    						   'component'.DS.'share'.DS.'list.phtml'));   	
    }    

    public function getToolbar() {
        return $this->toolbar;
    }

    public function getGrid() {
        return $this->grid;
    }

    public function getPagination() {
        return $this->pagination;
    }

    protected function getPaginationUrl($parameters = NULL) {
        if (is_null($parameters)) {
            $parameters = $this->getRequest()->getAllParameters();
        }
        return $this->getUrl(array_merge($parameters, array('pageindex' => '{index}', 'pagesize' => '{size}')));
    }

    protected function getSortUrl($parameters = NULL) {
        if (is_null($parameters)) {
            $parameters = $this->getRequest()->getAllParameters();
        }
        return $this->getUrl(array_merge($parameters, array('sort' => '{field}', 'dir' => '{direction}')));
    }

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('selector');
        $group->addButton($this->__('share.button.selectAll'))
                ->bindEvent('click', "Kdf.Ui.getGrid('" . $this->getGrid()->getId() . "').selectAll()");
        $group->addButton($this->__('share.button.cancelSelected'))
                ->bindEvent('click', "Kdf.Ui.getGrid('" . $this->getGrid()->getId() . "').cancelSelected()");
        $group->addButton($this->__('share.button.selectInverse'))
                ->bindEvent('click', "Kdf.Ui.getGrid('" . $this->getGrid()->getId() . "').selectInverse()");
    }

    protected function buildGrid($grid) {

    }

    protected function buildPagination($pagination) {
        $pagination->setFirstPageText($this->__('share.pagination.firstPage'))
                ->setLastPageText($this->__('share.pagination.lastPage'))
                ->setNextPageText($this->__('share.pagination.nextPage'))
                ->setPrevPageText($this->__('share.pagination.prevPage'))
                ->setPageSizeText($this->__('share.pagination.pageSize'))
                ->setInformationTextFormat($this->__('share.pagination.information'))
                ->setPageSizes($this->getDomain()->getApplication()->getConfig()->getSetting('pagination.sizes'))
                ->setPageIndex($this->getRequest()->getParameter('pageindex', 1))
                ->setPageSize($this->getRequest()->getParameter('pagesize', 20));
    }

    public function render() {
        $this->buildGrid($this->grid);
        $this->buildToolbar($this->toolbar);
        $this->buildNavigation($this->navigation);
        $this->buildPagination($this->pagination);
        $this->getTemplate()
                ->assign('toolbar', $this->getToolbar())
                ->assign('grid', $this->getGrid())
                ->assign('pagination', $this->getPagination())
                ->assign('navigation', $this->getNavigation());
        return parent::render();
    }

}